<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ page isELIgnored="false" %>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <meta http-equiv="Pragma" content="no-cache">
    <meta http-equiv="Cache-Control" content="no-cache">
    <meta http-equiv="Expires" content="0">
    <title>后台管理</title>
    <link href="/css/login.css" rel="stylesheet" type="text/css"/>
    <link href="/layui/css/layui.css" rel="stylesheet" type="text/css"/>
</head>

<body>
<div class="login_box">
    <div class="login_l_img"><img src="/images/login-img.png"/></div>
    <div class="login">
        <div class="login_logo"><a href="#"><img src="/images/login_logo.png"/></a></div>
        <div class="login_name">
            <p style="font-weight: bold">学生档案报名管理</p>
        </div>
        <%--        onsubmit="return login();"--%>
        <div>
            <input name="username" type="text" value="" placeholder="请填入用户名">
            <input name="password" type="password" id="password" placeholder="请填入密码"/>
            <div class="tips dis" style="color: red;margin-bottom: 10px">用户名或密码不能为空</div>
            <input value="登录" id="de" style="width:45%;background-color: #009688"  type="submit" onclick="login();">
            <a href="/register" style="width:45%;float: right;"> <input value="注册"  type="button"></a>
        </div>
    </div>

</div>
<div style="text-align:center;">

</div>

</body>
<script src="/js/jQuery-2.1.4.min.js"></script>
<script src="/js/bootstrap.min.js" type="text/javascript"></script>
<script src="/layui/layui.js"></script>
<script>
    //JavaScript代码区域
    layui.use('layer', function () {
        var layer = layui.layer;

    });
</script>

<script src="/js/login.js"></script>
<script>
    $("body").keydown(function(e) {
        if (event.keyCode == "13") {//keyCode=13是回车键
            // $("#de").click();

            var user = $('input[name="username"]').val();
            var pwd = $('input[name="password"]').val();

            if (user == '' || pwd == '') {
                $(".tips").removeClass("dis");
                $(".tips").addClass("layui-anim");
                $(".tips").addClass("layui-anim-upbit");

                return false;
            } else {
                $(".tips").addClass("dis");

            }

            $.ajax({
                url: '/login',
                method: "post",
                data: {userName: user, password: pwd},
                dataType: 'json',
                success: function (data) {
                    if (data.code == 0) {
                        layer.msg(data.msg);

                        // $("#de").unbind('click');
                        //前端设置登录成功后不能再提交
                        setTimeout(function () {
                            window.location.href = '/manage';

                        }, 700);
                        // $('#de').attr("disabled","disabled")
                        $('input[name="username"]').val('');
                        $('input[name="password"]').val('');
                    }else {
                        layer.msg(data.msg);
                        // setTimeout(function () {
                        //     window.location.href = '/';
                        // }, 1000);
                    }
                }
            })
        }
    });
</script>

</html>